import React, { Component } from 'react'
import PropTypes from 'prop-types'
import './index.css'

export default class Footer extends Component {

  static propTypes = {
    deleteTodos: PropTypes.func.isRequired,
    selectAll: PropTypes.func.isRequired,
    todos: PropTypes.array.isRequired,
  }

  render() {
    const { todos } = this.props;
    const total = todos.length;
    const sum = todos.reduce((pre, cur) => {
      return pre + (cur.isCheck ? 1 : 0);
    }, 0);
    return (
      <div className="todo-footer">
        <label>
          <input
            onChange={(event) => { this.props.selectAll(event.target.checked) }}
            checked={sum === total && total !== 0}
            type="checkbox"
          />
        </label>
        <span>
          <span>已完成{sum}</span> / 全部{total}
        </span>
        <button
          onClick={this.props.deleteTodos}
          className="btn btn-danger"
        >清除已完成任务</button>
      </div>
    )
  }
}
